package com.sysu.minsysu.zdkb;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import com.sysu.R;

public class ZhongDaKeBiao extends Activity{

	SimpleAdapter mAdapter;
	
	@Override
	public void onCreate( Bundle savedInstanceState ){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gridmainlayout);
		GridView gridView = (GridView)findViewById(R.id.gridview);
		mAdapter = new SimpleAdapter(this, getData(), R.layout.view_appmain, new String[]{ "image", "text" }, new int[]{R.id.imageView,R.id.textView});
		gridView.setAdapter(mAdapter);
		gridView.setNumColumns(2);
		gridView.setOnItemClickListener(new MyOnItemClickListener());
	}
	
	@Override
	public boolean onKeyDown( int keyCode, KeyEvent event){
		if( keyCode==KeyEvent.KEYCODE_BACK)
			return false;
		else return super.onKeyDown(keyCode, event);
	}

	private class MyOnItemClickListener implements OnItemClickListener{

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
			Intent intent ;
			switch( position ){
			case 0:
				intent = new Intent( ZhongDaKeBiao.this, SelectCoursesActivity.class);
				startActivity(intent);
				break;
			case 1:
				intent = new Intent( ZhongDaKeBiao.this, FindClassRooms.class);
				startActivity(intent);
				break;
			case 2:
				intent = new Intent( ZhongDaKeBiao.this, MyCourseActivity.class);
				startActivity(intent);
				break;
			}
		}
	}
	
	int[] ids = new int[]{
			R.drawable.gerenkebiao_xuanke,
			R.drawable.gerenkebiao_keshichaxun,
			R.drawable.gerenkebiao_wodekebiao,
	};
	String[] names = new String[]{
			"选课",
			"课室查询",
			"我的课表",
	};
	
	private List< Map<String, Object> > getData(){
		List< Map<String, Object>> list = new ArrayList<Map<String,Object>>();
			
		for( int i=0; i<ids.length; i++ ){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("image", ids[i]);
		map.put("text", names[i]);
		list.add(map);
		}
			
		return list;
	}
}
